import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = ()=>import('@/views/Login/login')
const Register = ()=>import('@/views/Register/register')
const UserInfo = ()=>import('@/views/UserInfo/userinfo')
const Home = ()=>import('@/views/Home/home')
Vue.use(VueRouter)
const routes = [
    {path:"/login",component:Login},
    {path:"/register",component:Register},
    {path:"/userinfo",component:UserInfo},
    {path:"/home",component:Home,meta:{isPasss:true}}
    
]

const router = new VueRouter({
    mode:'history',
    routes
})
router.beforeEach((to, from, next) => {
  let token = sessionStorage.getItem('token')
if(token || to.path == '/login' || to.path == '/register' || to.meta.isPasss){
    next()
}else{
    next('/login')
}
    
})
export default router